﻿using King.Engine.Content;
using King.Engine.Core;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BreacherCreature.Components.Lights
{
    public class LightArea : LightField
    {
        #region Fields

        Texture2D _texture;

        #endregion

        #region Properties

        /// <summary>
        /// The bounds of the light area
        /// </summary>
        public Rectangle Bounds;

        #endregion

        #region Constructor

        public LightArea(int x, int y, int width, int height, Color lightColor, int framesOn, int framesOff, bool startOn) : base(framesOn, framesOff, startOn)
        {
            Bounds = new Rectangle(x, y, width, height);
            LightColor = lightColor;
            _texture = ContentLoader.Get<Texture2D>("Pixel");
        }
        public LightArea(int x, int y, int width, int height, Color lightColor) : base()
        {
            Bounds = new Rectangle(x, y, width, height);
            LightColor = lightColor;
            _texture = ContentLoader.Get<Texture2D>("Pixel");
        }

        #endregion

        #region Public Methods

        public override void Draw()
        {
            if (TurnedOn)
                if (_flickerType == FlickerType.None || _flicker.IsOn)
                    Screen.Draw(false, _texture, Bounds, null, LightColor * LightTransparency, 0, Vector2.Zero, SpriteEffects.None, DrawDepths.LIGHT);
        }

        /// <summary>
        /// Determines whether the a rectangle is inside the area
        /// </summary>
        /// <param name="rect">The rect to be checked</param>
        /// <returns>Whether the area contains the rectangle</returns>
        public override bool CollidesWith(Rectangle rect)
        {
            if (TurnedOn)
                if (_flickerType == FlickerType.None || _flicker.FullyOn)
                    return Bounds.Intersects(rect);

            return false;
        }

        #endregion
    }
}
